<?php

namespace App\Exports;

use App\Models\Housings;
use App\Models\Report;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;


class HousingsExport implements FromCollection,WithHeadings,WithMapping
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $query=Housings::query();
        if (isset($this->filters['ids'])) {
            $query->whereIn('id', explode(',',$this->filters['ids']));
        }
        return $query->get();
    }

    public function headings(): array
    {
        return [
            '房屋报备ID',
            '出租类型',
            '房屋地址',
            '申报状态',
            '注销状态',
            '数据更新时间',
            '数据推送时间',
            // ... 其他列标题
        ];
    }

    public function map($housings): array
    {
        // 假设订单有 id 和 total 字段
        //        $housings = $inspection->housings;
        $orderData[] = [
            $housings['id'],
            $housings['rental_type'],
            $housings['hou_address'],
            $housings['type'],
            $housings['register_type'],
            "",
            ""
        ];
        // 展开订单数据，以便每行都有用户信息和对应的订单信息
        return array_merge(...$orderData);
    }
}
